﻿
using EasyDDD.AdminModule.Repository;

namespace EasyDDD.AdminModule.Application
{
    internal class CommandUnitOfWorkBehavior<TCommand, TResponse>(AdminModuleRepositoryDbContext context)
        : EasyDDD.Application.ICommandUnitOfWorkBehavior<TCommand, TResponse>
        where TCommand : ICommandBase
    {
        public async Task<TResponse> Handle(TCommand request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
        {
            var response = await next();
            await context.SaveUnitOfWorkAsync(cancellationToken);
            return response;
        }
    }
}
